//
//  RemoteAVViewController.m
//  OST
//
//  Created by mac on 13-7-11.
//  Copyright (c) 2013年 mac. All rights reserved.
//

#import "RemoteAVViewController.h"
#import "RemoteData.h"
#import "CommonData.h"

@interface RemoteAVViewController ()

@end

@implementation RemoteAVViewController
@synthesize data;
@synthesize btn_type1,btn_type2,btn_type3,btn_type4,btn_type5,btn_type6;

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    btn_type_arrays = [NSArray arrayWithObjects:btn_type1,btn_type2,btn_type3,btn_type4,btn_type5,btn_type6, nil];
    
    [activity startAnimating];
    [[RemoteData sharedInstance]getDataWithDataRecivedBlock:^(id xdata) {
        [activity stopAnimating];
        
        for (NSDictionary *dict in xdata) {
            NSString *zid = [dict objectForKey:@"zid"];
            NSString *xzid = [data objectForKey:@"zid"];
            if ([zid isEqualToString:xzid]) {
                NSString *code = [dict objectForKey:@"code"];
                if ([code length]>=12) {
                    int index = 0 ;
                    for (UIButton *btn in btn_type_arrays) {
                        NSString *tag = [code substringWithRange:NSMakeRange(index*2, 2)];
                        btn.tag = [tag intValue];
                        index++;
                    }
                }
            }
        }
    }];
}

-(IBAction)typeClicked:(UIButton *)sender
{
    for (UIButton *btn in btn_type_arrays) {
        btn.selected = NO;
    }
    sender.selected = YES;
}

-(IBAction)cmdClicked:(UIButton *)sender
{
    NSString *zid = [data objectForKey:@"zid"];
    int type =0;
    for (UIButton *btn in btn_type_arrays) {
        if (btn.selected) {
            type = btn.tag;
        }
    }
    
    CommonData *commonData4 = [[CommonData alloc]initWidthUrl:[NSString stringWithFormat:@"cgi-bin/command_class_AV.cgi?ZID=%@&CH=%d&COMMAND=AV_SET&Value=%d",zid,type,sender.tag ]];
    commonData4.justCommand = YES;
    [activity startAnimating];
    [commonData4 getDataWithDataRecivedBlock:^(id xdata) {
        [activity stopAnimating];
        NSLog(@"%@",xdata);
    }];
    
}


@end
